﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Micro.Core.ApiConsumer.ActionAttributes
{
    /// <summary>
    /// 接口Host地址特性
    /// </summary>
    public sealed class HttpHostAttribute : ApiActionAttribute
    {
        /// <summary>
        /// 完整域名地址（http://example.com.cn）
        /// </summary>
        public Uri Host { get; set; }

        /// <summary>
        /// 设置host特性为最高优先级
        /// </summary>
        public override int OrderIndex { get => Int32.MinValue; }

        /// <summary>
        /// 特性构造函数
        /// </summary>
        /// <param name="host">域名地址</param>
        public HttpHostAttribute(string host)
        {
            this.Host = new Uri(host, UriKind.Absolute);
        }

        public override void Compose(HttpRequest request)
        {
            request.Url = Host;
        }
    }
}
